#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : lee

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import pymel.core as pm
    import jarryLibs.mayakit.MayaUtils as mu
    reload(mu)
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class HairGroupNameCheck(CheckBase):
    def __init__(self):
        super(HairGroupNameCheck, self).__init__()
        pass

    def check_groups_name(self):
        miss_groups = []
        top_group_name = "cfx_grp"
        if not cmds.objExists(top_group_name):
            miss_groups.append(top_group_name)
            return

        standard_groups, set_groups = self.get_standard_groups()
        miss_groups = []
        for group in cmds.listRelatives(top_group_name, c=True):
            if group not in standard_groups:
                miss_groups.append(group)

        for set in set_groups:
            if not cmds.objExists(set):
                miss_groups.append(set)

        return miss_groups

    def get_standard_groups(self):
        # 通过文件名称获取资产信息
        maya_file = mu.sceneName()
        file_name = os.path.basename(maya_file)
        asset_short_type = file_name.split("_")[0]
        asset_name = file_name.split("_")[1]

        standard_groups_name = []
        groups_type = ["pgYetiMaya_dyn", "pgYetiMaya_static", "growMesh",
                       "pgYetiGroom", "guideCurve", "referenceMesh",
                       "tracker", "furMesh", 'render']
        for type in groups_type:
            standard_groups_name.append("{0}_{1}_{2}_grp".format(asset_short_type, asset_name, type))

        # 添加set组
        standard_set_groups = []
        standard_set_groups.append("{0}_{1}_hair_Sets".format(asset_short_type, asset_name))

        return standard_groups_name, standard_set_groups

    def check(self):
        result_proc = self.check_groups_name()
        if result_proc:
            result_log = u'Error:%s名称不匹配\n' % result_proc
        else:
            result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        pass
